from typing import *


class Solution:

    def maximumRows(self, matrix: List[List[int]], numSelect: int) -> int:
        m, n = len(matrix), len(matrix[0])
        mx = 1 << n
        l = []
        for i in range(mx):
            if i.bit_count() == numSelect:
                l.append(i)
        r = []
        for i in range(m):
            c = 0
            for j in range(n):
                if matrix[i][j] == 1:
                    c |= 1 << j
            r.append(c)
        ans = 0
        for v in l:
            c = 0
            for i in r:
                if (v ^ i) | i == v:
                    c += 1
            ans = max(c, ans)
        return ans
    
s = Solution()
print(s.maximumRows(matrix = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]], numSelect = 2))